﻿using Serilog;
using Serilog.Events;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace ToolHelp
{
    public static  class SerilLogHelper
    {
        public static void WriteLog(string messge)
        {
            Log.Logger = new LoggerConfiguration()
                   .MinimumLevel.Debug()
                   .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
                  .WriteTo.File(Path.Combine(ConfigHelper.GetValue("SerilLog:Path"),"WritrLog",$"{DateTime.Now:yyyy:MM:dd}.txt"))
                   .CreateLogger();
            Log.Information($"{DateTime.Now}：{messge}");
            Log.CloseAndFlush();
        }
        public static void ErrorLog(string messge,Exception ex)
        {
            
            Log.Logger = new LoggerConfiguration()
                 .MinimumLevel.Debug()
                 .MinimumLevel.Override("Microsoft", LogEventLevel.Error)
              .WriteTo.File(Path.Combine(ConfigHelper.GetValue("SerilLog:Path"), $"ErrorLog", $"{DateTime.Now.ToString("yyyy-MM-dd")}.txt"))
                 .CreateLogger();
            Log.Error(ex,messge);
            Log.CloseAndFlush();
        }
        public static void WarnLog(string messge)
        {
            Log.Logger = new LoggerConfiguration()
               .MinimumLevel.Debug()
               .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
              .WriteTo.File(Path.Combine(ConfigHelper.GetValue("SerilLog:Path"), $"WarnLog",$"{DateTime.Now.ToString("yyyy-MM-dd")}.txt"))
               .CreateLogger();
            Log.Warning($"{DateTime.Now}：{messge}");
            Log.CloseAndFlush();
        }
    }
}
